package com.example.customcomposedemo

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.example.customcomposedemo.customview.FocusableSample
import com.example.customcomposedemo.customview.LikeButton
import com.example.customcomposedemo.ui.theme.ComposeAnimationDemoTheme
import java.lang.Math.sin
import java.lang.StrictMath.cos

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            ComposeAnimationDemoTheme {
                // A surface container using the 'background' color from the theme
                // ClockFace(1,30)
               // LikeButton()
                FocusableSample()
            }
        }
    }
}


@Composable
fun ClockFace(hours: Int, minutes: Int) {
    Canvas(modifier = Modifier.fillMaxSize()) {
        val canvasWidth = size.width
        val canvasHeight = size.height
        val radius = canvasWidth / 2 * 0.8f // 表盘半径
        val centerX = canvasWidth / 2
        val centerY = canvasHeight / 2

        // 绘制表盘刻度
        repeat(12) { index ->
            drawLine(
                color = Color.Black,
                start = Offset(centerX, centerY - radius),
                end = Offset(
                    (centerX + (radius * sin(Math.toRadians(index * 30.0)))).toFloat(),
                    (centerY - (radius * cos(Math.toRadians(index * 30.0)))).toFloat()
                ),
                strokeWidth = 4.dp.toPx()
            )
        }

        // 绘制时针
        val hourAngle = (hours % 12 + minutes / 60.0) * 30.0
        drawLine(
            color = Color.Black,
            start = Offset(centerX, centerY),
            end = Offset(
                (centerX + (radius * 0.5f * sin(Math.toRadians(hourAngle)))).toFloat(),
                (centerY - (radius * 0.5f * cos(Math.toRadians(hourAngle)))).toFloat()
            ),
            strokeWidth = 12.dp.toPx()
        )

        // 绘制分针
        val minuteAngle = minutes * 6.0
        drawLine(
            color = Color.Black,
            start = Offset(centerX, centerY),
            end = Offset(
                (centerX + (radius * 0.7f * sin(Math.toRadians(minuteAngle)))).toFloat(),
                (centerY - (radius * 0.7f * cos(Math.toRadians(minuteAngle)))).toFloat()
            ),
            strokeWidth = 6.dp.toPx()
        )
    }
}



